<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        title {
            line-height: 40px;
            font-weight: bold;
            text-align: center;
            margin-left: 10px;
        }

        .list .item {
            display: flex;
        }

        .list .left {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 10px;
        }

        .list .left img {
            width: 70px;
            border-radius: 10px;
        }

        .list .middle .name {
            margin-top: 10px;
            font-weight: bold;
        }

        .list .middle .desc {
            font-size: 12px;
            color: orange;
        }

        .list .right {
            display: flex;
            justify-content: space-between;
            align-items: center;
            /* margin: 10px; */
        }

        .list .right .jian {
            margin-left: 50px;
            width: 20px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            border: 1px solid #00a6ff;
            border-radius: 100%;

        }

        .list .right .jia {
            width: 20px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            background-color: #00a6ff;
            border-radius: 100%;
        }

        .list .right .status {
            padding-left: 20px;
            padding-right: 20px;
        }

        .dibu {
            position: relative;
            width: 100%;
            height: 70px;
            background-color: #474747;
            display: flex;
        }

        .dibu img {
            width: 50px;
            border-radius: 10px;
            margin-left: 10px;
            margin-top: 10px;
        }

        .dibu .middle .dian {
            width: 20px;
            height: 20px;
            background-color: red;
            position: absolute;
            top: 5px;
            left: 50px;
            border-radius: 100%;
            line-height: 20px;
            text-align: center;
        }

        .dibu .middle .money {
            margin-left: 15px;
            margin-top: 10px;
            color: aliceblue;
            font-size: 20px;
        }

        .dibu .right button {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            background-color: #02d562;
            border: none;
            margin-left: 70px;
            font-size: 20px;
            color: aliceblue;
            margin-top: 15px;
            border-radius: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="title">已购商品<span v-text="totalstatus()"></span></div>
        <div class="list">
            <div class="item" v-for="(item,index) in tasklist" v-bind:key="index">
                <div class="left">
                    <img v-bind:src="item.pic" alt="">
                </div>
                <div class="middle">
                    <div class="name">{{item.name}}</div>
                    <div class="desc">{{item.desc}}</div>
                </div>
                <div class="right">
                    <div class="jian" @click="sub(item)">-</div>
                    <div class="status">{{item.status}}</div>
                    <div class="jia" @click="add(item)">+</div>
                </div>
            </div>
        </div>
    </div>
    <div class="dibu">
        <div class="left">
            <img src="./img/4.jpg" alt="">
        </div>
        <div class="middle">
            <div class="money">￥{{totaldesc}}</div>
            <div class="dian" v-text="totalstatus()"></div>
        </div>
        <div class="right">
            <button>去结算</button>
        </div>
    </div>
    <script src="./vue-2.5.21.js"></script>
</body>

</html>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            tasklist: [
                { id: 1, pic: './img/1.jpg', name: '秋刀鱼斤', desc: '￥35', status: 1 },
                { id: 2, pic: './img/2.jpg', name: '鲜大带鱼', desc: '￥45', status: 1 },
                { id: 3, pic: './img/3.jpg', name: '大皮皮虾', desc: '￥55', status: 1 }
            ]
        },
        methods: {
            add(item) {
                if (item.status < 5) {
                    item.status++
                }
            },
            sub(item) {
                if (item, status > 1) {
                    item.status--
                }
            },
            totalstatus() {
                var totalstatus = 0
                this.tasklist.forEach((item, index) => {
                    totalstatus += item.status
                })
                return totalstatus
            },
            totaldesc() {
                var totaldesc = 0
                this.tasklist.forEach((item, index) => {
                    totaldesc += item.desc * item.status
                })
                return totaldesc
            },
            clear() {
                this.tasklist = []
            }
        }
    })

</script>